const { query } = require("../db/query")

module.exports = {
  // 获取论坛列表
  getForumList: async () => {
    // 调用query发送sql语句到mysql进行获取论坛列表
    return await query("select * from forum")
  },
  // 查询论坛
  queryForumList: async (username, title) => {
    // 调用query发送sql语句到mysql进行查询论坛
    return await query("select * from forum where username=? or title =?", [username, title])
  },
  // 删除论坛
  removeForum: async (id) => {
    // 调用query发送sql语句到mysql进行删除论坛
    return await query("delete from forum where id=?", [id])
  },
  // 获取论坛详情数据
  getForumDetails: async (id) => {
    // 调用query发送sql语句到mysql进行获取论坛详情数据
    return await query("select * from forum where id =?", [id])
  },
  // 获取论坛评论数据
  getComment: async (id, current, pagesize) => {
    const currentSize = (current - 1) * pagesize;
    // 调用query发送sql语句到mysql进行获取论坛评论数据
    return await query("select * from onecomment where forum_id =? limit ?,?", [id, currentSize, parseInt(pagesize)])
  },
  // 获取论坛评论数据
  getAllComment: async (id) => {
    // 调用query发送sql语句到mysql进行获取论坛评论数据
    return await query("select * from onecomment where forum_id =?", [id])
  },
  // 删除论坛评论
  delComment: async (id) => {
    // 调用query发送sql语句到mysql进行删除论坛评论
    return await query("delete from onecomment where id=?", [id])
  },
  // 发表评论
  publishComment: async (forum_id, user_id, username, avatar, content, createtime) => {
    // 调用query发送sql语句到mysql进行删除论坛评论
    return await query("insert into onecomment(forum_id, user_id, username, avatar, content, createtime) values(?,?,?,?,?,?)", [forum_id, user_id, username, avatar, content, createtime])
  },
}